﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Game_Fly.Code.AuxiliaryAction;

namespace Game_Fly.Code
{
    public class BackGround
    {
        //1.字段变量：xy坐标，小兵背景，boss背景，游戏阶段，背景移动速度
        int x;
        int y;
        Image backgroundImage;
        Image backgroundBossImage;
        int width;
        int height;
        int phase;
        int speed;
        public int X
        {
            set { x = value; }
            get { return x; }
        }
        public int Width
        {
            set { width = value; }
            get { return width; }
        }

        public int Height
        {
            set { height = value; }
            get { return height; }
        }
        //2.属性方法
        //3.构造方法
        public BackGround()
        {
            backgroundImage = GameImage.BJ1;
            backgroundBossImage = GameImage.BJ2;
            x = (GameUI.GameForm.ClientSize.Width - backgroundImage.Width) / 2;
            y = backgroundBossImage.Height - backgroundImage.Height;
            phase = 1;
            speed = 1;
            width = backgroundImage.Width;
            height = backgroundImage.Height;
        }
        //4.特征方法
        public void Draw(Graphics g)
        {
            switch (phase)
            {
                case 1:
                    g.DrawImage(backgroundImage, x, y, backgroundImage.Width, backgroundImage.Height);
                    break;
                case 2:
                    g.DrawImage(backgroundBossImage, x, y, backgroundImage.Width, backgroundImage.Height);
                    g.DrawImage(backgroundBossImage, x, y - backgroundBossImage.Height, backgroundImage.Width, backgroundImage.Height);
                    break;
            }
            new IsHit(g).Enemy1_IsHit();//敌机爆炸特效，，敌机和子弹的碰撞
            new IsHit(g).Enemy1_Plane();//玩家与敌机相撞
            new IsHit(g).Enemy2_IsHit();//敌机爆炸特效，，敌机和子弹的碰撞
            new IsHit(g).Enemy2_Plane();//玩家与敌机相撞
            new IsHit(g).EnemyBoss_IsHit();//敌机爆炸特效，，敌机和子弹的碰撞
            new IsHit(g).EnemyBoss_Plane();//玩家与敌机相撞
            new IsHit(g).BulletTwoPrize_Plane();//玩家与奖品相交
            new IsHit(g).Enemy1_BulletTwo_IsHit();
            new IsHit(g).Enemy2_BulletTwo_IsHit();
            new IsHit(g).EnemyBoss_BulletTwo_IsHit();
            new IsHit(g).LifPrize_Plane();//生命投送

            //绘制文本计数
            g.DrawString("分数：" + GameUI.GamePlane.HitNumber + "  +", new Font("微软雅黑", 15), Brushes.Green, new PointF(0, GameUI.GamePlane.Y));
            //本局等级
            g.DrawString("等级：" + GameUI.GamePlane.Grade + "  +", new Font("微软雅黑", 15), Brushes.Green, new PointF((GameUI.GameForm.ClientSize.Width - GameUI.GameBackGround.backgroundImage.Width) / 2 + (GameUI.GameBackGround.backgroundImage.Width), GameUI.GamePlane.Y));
            //生命
            g.DrawString("生命：" + GameUI.GamePlane.Life, new Font("微软雅黑", 15), Brushes.Green, new PointF(0, GameUI.GamePlane.Y / 2));
        }

        Enemy1 enemy1 = new Enemy1();
        Enemy2 enemy2 = new Enemy2();
        EnemyBoss enemyBoss = new EnemyBoss();
        BulletTwoPrize btp = new BulletTwoPrize();
        LifePrize lifePrize = new LifePrize();
        int time1 = 0;//敌机1的累计变量
        int time2 = 0;//敌机12的累计变量
        int timeBoss = 0;//敌机boss的累计变量
        int timePrize = 0;
        int timelifePrize = 0;//
        public void Update(int frame)
        {
            //往下移动
            y += speed;
            //判断进入的阶段
            time1++; time2++; timeBoss++; timePrize++; timelifePrize++;
            switch (phase)
            {
                case 1:
                    if (y >= 0)
                    {
                        //小兵阶段走完进入boss阶段
                        phase = 2;
                        backgroundImage = GameImage.BJ1;
                        //发放敌机1
                        if (time1 >= enemy1.Count)
                        {
                            time1 = 0;
                            ProductionEnemy.ProductionEnemy1();
                        }
                        //发放敌机2
                        if (time2 >= enemy2.Count)
                        {
                            time2 = 0;
                            ProductionEnemy.ProductionEnemy2();
                        }
                        //发放敌机Boss
                        if (timeBoss >= enemyBoss.Count)
                        {
                            timeBoss = 0;
                            ProductionEnemy.ProductionEnemyBoss();
                        }
                        //发放奖励子弹
                        if (timePrize >= btp.Count)
                        {
                            timePrize = 0;
                            ProductionEnemy.ProductionBulletTwoPrize();
                        }
                        //发放生命
                        if (timelifePrize >= lifePrize.Count)
                        {
                            timelifePrize = 0;
                            ProductionEnemy.ProductionLifePrize();
                        }
                    }
                    break;
                case 2:
                    if (y >= backgroundBossImage.Height)
                        //boss走完，，在把图拉回去
                        y -= backgroundBossImage.Height;
                    //发放敌机1
                    if (time1 >= enemy1.Count)
                    {
                        time1 = 0;
                        ProductionEnemy.ProductionEnemy1();
                    }
                    //发放敌机1
                    if (time2 >= enemy2.Count)
                    {
                        time2 = 0;
                        ProductionEnemy.ProductionEnemy2();
                    }
                    //发放敌机Boss
                    if (timeBoss >= enemyBoss.Count)
                    {
                        timeBoss = 0;
                        ProductionEnemy.ProductionEnemyBoss();
                    }
                    //发放奖励子弹
                    if (timePrize >= btp.Count)
                    {
                        timePrize = 0;
                        ProductionEnemy.ProductionBulletTwoPrize();
                    }
                    //发放生命
                    if (timelifePrize >= lifePrize.Count)
                    {
                        timelifePrize = 0;
                        ProductionEnemy.ProductionLifePrize();
                    }
                    break;
            }
        }
    }
}
